class Event {
    constructor() {
        this.queue = {};
        this.onceQueue = {};
    }

    $on(name, callback) {
        this.queue[name] = this.queue[name] || [];
        this.queue[name].push(callback);
    }

    $once(name, callback) {
        this.onceQueue[name] = this.onceQueue[name] || [];
        this.onceQueue[name].push(callback);
    }

    $off(name, callback) {
        if (callback) {
            if (this.queue[name]) {
                for (var i = 0; i < this.queue[name].length; i++) {
                    if (this.queue[name][i] === callback) {
                        this.queue[name].splice(i, 1);
                        break;
                    }
                }
            }
        } else {
            delete this.queue[name];
        }
    }

    $emit(name, data) {
        if (this.queue[name]) {
            this.queue[name].forEach(function (callback) {
                callback(data);
            });
        }
        if (this.onceQueue[name]) {
            this.onceQueue[name].forEach(function (callback) {
                callback(data);
            });
            delete this.onceQueue[name];
        }
    }
}

export default new Event();




export const ISSUES_LIST_INVOKE = "issuesListInvoke";
export const DEL_ISSUES_BTN = "delIssuesBtn";
